<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>12306后台管理系统</title>
  <link rel="stylesheet" href="layui/css/layui.css">
  <script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header layui-bg-blue">
    <div class="layui-logo layui-hide-xs"  style="justify-content:center;color:red;text-shadow: 2px 2px black;">
    	12306
		<img alt="" src="images/loading4.gif" style="width:70px;height:70px">
		
	</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <!-- 移动端显示 -->
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
        <i class="layui-icon layui-icon-spread-left"></i>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
        <a href="javascript:;" style="font-weight:bold;color:black" id="adminUserName">${loginAdmin}</a>
        <dl class="layui-nav-child">
          <dd><a href="exit.do">退出</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-blue">
    <div class="layui-side-scroll ">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree layui-bg-blue" lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">车站</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">失信人员名单</a></dd>
            <dd><a href="javascript:;">车票</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">个人中心</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">建议</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item"><a href="javascript:;">用户</a></li>
        <li class="layui-nav-item"><a href="">管理人员</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
    	<div class="layui-tab layui-tab-brief " lay-filter="docDemoTabBrief">
  			<ul class="layui-tab-title">
    			<li class="layui-this">管理员</li>
    			<li>用户</li>
    			<li>用户建议</li>
    			<li>失信人员名单</li>
    			<li>车票</li>
  			</ul>
  			<div class="layui-tab-content ">
  				<div class="layui-tab-item layui-show" sytle="height:20px">
  					<div class="demoTable">
  						搜索：
  						<div class="layui-inline">
    						<input class="layui-input" name="id" id="demoReload" autocomplete="off" placeholder="请输入管理员名">
  						</div>
  						<button class="layui-btn" data-type="reload">搜索</button>
					</div>
    				<table id="demoAdmin" lay-filter="testAdmin"></table>
    			</div>
    			<div class="layui-tab-item">
    				<div class="demoUserTable">
  						搜索：
  						<div class="layui-inline">
    						<input class="layui-input" name="id" id="demoUserReload" autocomplete="off" placeholder="请输入建议人名或身份Id">
  						</div>
  						<button class="layui-btn" data-type="reload">搜索</button>
					</div>
    				<table id="demo" lay-filter="test"></table>
    			</div>
    			<div class="layui-tab-item">
    				<div class="demoSuggestionTable">
  						搜索：
  						<div class="layui-inline">
    						<input class="layui-input" name="id" id="demoSuggestionReload" autocomplete="off" placeholder="请输入建议人名或身份Id">
  						</div>
  						<button class="layui-btn" data-type="reload">搜索</button>
					</div>
    				<table id="demoSuggestion" lay-filter="testdemoSuggestion"></table>
    			</div>
    			<div class="layui-tab-item">
    				<div class="demoLcuTable">
  						搜索：
  						<div class="layui-inline">
    						<input class="layui-input" name="id" id="demoLcuReload" autocomplete="off" placeholder="请输入失信人名或身份Id">
  						</div>
  						<button class="layui-btn" data-type="reload">搜索</button>
					</div>
					<table id="loseCreditUser" lay-filter="loseCreditUserTest"></table></div>
    			<div class="layui-tab-item">车票</div>
  			</div>
		</div>
	

    </div>
  </div>
  
  <div class="layui-footer" style="text-align:center;color:red;font-weight:bold">
    <!-- 底部固定区域 -->
  	仅供学习参考使用
  </div>
</div>
<script src="layui/layui.js"></script>
<script>
//JS 
layui.use(['element', 'layer', 'util','table'], function(){
  var element = layui.element
  ,layer = layui.layer
  ,util = layui.util
  ,table = layui.table
  ,$ = layui.$;
  
  //头部事件
  util.event('lay-header-event', {
    //左侧菜单事件
    menuLeft: function(othis){
      layer.msg('展开左侧菜单的操作', {icon: 0});
    }
    ,menuRight: function(){
      layer.open({
        type: 1
        ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
        ,area: ['260px', '100%']
        ,offset: 'rt' //右上角
        ,anim: 5
        ,shadeClose: true
      });
    }
  });
  
  //用户
  var tablename = table.render({
      elem:"#demo",
      height:'full-220',
      url:'/12306/UserShowServlet.do',
      toolbar:'#toolbarDemo1',
      method:'post',
      page:true,
      cols:[[
          {type:'checkbox',fixed:'left'},
          {field:'user_id',title:'ID',width:100,sort:true},
          {field:'user_name',title:'用户名',width:100},
          {field:'user_password',title:'密码',width:100},
          {field:'user_real_name',title:'真名',width:100},
          {field:'user_id_type',title:'身份证类型',width:100},
          {field:'user_id_num',title:'身份证号',width:100},
          {field:'user_sex',title:'性别',width:100},
          {field:'user_phone',title:'电话号码',width:100},
          {field:'user_email',title:'邮箱',width:100},
          {field:'passenger_type',title:'旅客类型',width:100},
          {field:'register_time',title:'注册时间',width:100},
          {field:'consumption_password',title:'支付密码',width:100},
          {field:'isdelete',title:'是否删除',width:100},
          {field:'right',title:'操作',width:150,toolbar:"#barDemo"}
      ]]
  });
  console.log(tablename.config)
  
  	//通过用户搜索，并执行重载
	 var $ = layui.$, activeUser = {
		    reload: function(){
		      var demoReload = $('#demoUserReload');
		      console.log(demoReload.val())
		      //执行重载
		      table.reload('demo', {
		 	    /* url:'/12306/SuggestionReload.do?key='+demoReload.val(), */
		 	    method:'post',
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		          key: {
		            key: demoReload.val()
		          }
		        }
		      });
		    }
		  };
		  
		  $('.demoUserTable .layui-btn').on('click', function(){
		    var type = $(this).data('type');
		    activeUser[type] ? activeUser[type].call(this) : '';
		  });
  
  //监听行事件
  table.on('tool(test)',function(obj){
    var data = obj.data;
    if (obj.event === 'del') {
      layer.confirm('是否删除？',function(index){
        var checkStatus = table.checkStatus('demo');
        if (checkStatus.data.length == 0) {
          layer.msg("请选择要删除的数据！");
        }else{
          var user_id = checkStatus.data[0].user_id;
          $.ajax({
            url:'/12306/DelUser.do?user_id='+user_id,
            type:'post',
            dataType:'text',
            success:function(){
              obj.del();
              layer.msg("删除成功！");
              table.reload('demo',{
                page:{
                  curr:tablename.config.page.curr
                },
                where:{
                  data:data
                }
              });
            },

            error:function() {
             layer.msg("删除失败！")
            }


          })
        }
      });



    }else if (obj.event === 'edit'){
        layer.open({
          type:2,
          title:'编辑用户信息',
          content:'editUser.jsp',
          maxmin:true,
          skin:'layui-layer-lan',
          area:['350px','600px'],
          btn:['确定','取消'],
          yes:function(index,layero){
             var user_id = $(layero).find('iframe')[0].contentWindow.user_id.value;
             var user_name = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_name").value;
             var user_password = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_password").value;
             var user_real_name = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_real_name").value;
             var user_id_type = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_id_type").value;
             var user_id_num = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_id_num").value;
             var user_sex = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_sex").value;
             var user_phone = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_phone").value;
             var user_email = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_email").value;
             var passenger_type = $(layero).find('iframe')[0].contentWindow.document.getElementById("passenger_type").value;
             var register_time = $(layero).find('iframe')[0].contentWindow.document.getElementById("register_time").value;
             var consumption_password = $(layero).find('iframe')[0].contentWindow.document.getElementById("consumption_password").value;
             var isdelete = $(layero).find('iframe')[0].contentWindow.document.getElementById("isdelete").value;
          
             obj.update({
                "user_id":user_id,
                "user_name":user_name,
                "user_password":user_password,
                "user_real_name":user_real_name,
                "user_id_type":user_id_type,
                "user_id_num":user_id_num,
                "user_sex":user_sex,
                "user_phone":user_phone,
                "user_email":user_email,
                "passenger_type":passenger_type,
                "register_time":register_time,
                "consumption_password":consumption_password,
                "isdelete":isdelete
             })

             $.ajax({
              url:'/12306/updateUser.do?user_id='+user_id+'&user_name='+user_name+'&user_password='+user_password+"&user_phone="+user_phone+"&user_email="+user_email+"consumption_password="+consumption_password,
              type:'post',
              dataType:'text',
              data:{
                "user_id":user_id,
                "user_name":user_name,
                "user_password":user_password,
                "user_real_name":user_real_name,
                "user_id_type":user_id_type,
                "user_id_num":user_id_num,
                "user_sex":user_sex,
                "user_phone":user_phone,
                "user_email":user_email,
                "passenger_type":passenger_type,
                "register_time":register_time,
                "consumption_password":consumption_password,
                "isdelete":isdelete
              },
              success:function(res){
                layer.msg("修改成功！");
                table.reload('demo',{
                  page:{
                    curr:tablename.config.curr
                  },
                  where:{
                    data:data
                  }
                });
              },
              error:function(){
                layer.msg("修改失败！");
              }
             })
             layer.close(index);

          },
          success:function(layero,index){
            var div = layero.find('iframe').contents().find("#userAdmin");
            var body = layer.getChildFrame('body',index);
            var ifrandWindow = window['layui-layer-iframe'+index];
            body.find('#user_id').val(data.user_id);
            body.find('#user_name').val(data.user_name);
            body.find('#user_password').val(data.user_password);
            body.find('#user_real_name').val(data.user_real_name);
            body.find('#user_id_type').val(data.user_id_type);
            body.find('#user_id_num').val(data.user_id_num);
            body.find('#user_sex').val(data.user_sex);
            body.find('#user_phone').val(data.user_phone);
            body.find('#user_email').val(data.user_email);
            body.find('#passenger_type').val(data.passenger_type);
            body.find('#register_time').val(data.register_time);
            body.find('#consumption_password').val(data.consumption_password);
            body.find('#isdelete').val(data.isdelete);
          }
        });
    }
  });
  
  //头工具栏事件
  table.on('toolbar(test)', function(obj){
	  var checkStatus = table.checkStatus(obj.config.id);
	  switch(obj.event){
	  	case 'delall'://批量删除
	  		layer.confirm('真的删除已选的数据吗？？', function(index){
	    		  var data = checkStatus.data;
	    	        var dataId = [];
	    	        if(data.length === 0){
	    	        	layer.msg("请选择所要删出的数据！！");
	    	        }else{
	    	        	for (var i = 0; i < data.length; i++) {
	        	        	dataId.push(data[i].user_id);
	        			}
	        	        //console.log(dataId)
	        	        $.ajax({
	        	        	url:'/12306/DelBatchUser.do? ids'+dataId,
	        	  	  		data:{"dataId":dataId},
	        	  	  		traditional:true,
	        	  	  		type:'post',
	        	  	  		dataType:'text',
	        	  	  		
	        	  	  		success:function(){
	        		  			layer.msg("删除成功！！");
	        		  		//重载
	              	  			table.reload('demo', {
	              	  				page: {
	              	  					curr: tablename.config.page.curr //重新从当前页开始
	              	  				}
	              	  				,where: {
	              	  					data:data
	              	  				}
	              	  				
	              	  			});
	        		  		},
	        		  		
	        		  		error:function(){
	        		  			layer.msg("删除失败！！");
	        		  		}

	        	        });
	    	        }
	    	        
	    	   });
	  	
	  	
	  	break;
	  }
  });
  
  
  
  
  
  //建议
  var tablenameSuggestion = table.render({
      elem:"#demoSuggestion",
      height:'full-220',
      url:'/12306/SuggestionShow.do',
      toolbar:'#toolbarSuggest',
      method:'post',
      page:true,
      cols:[[
          {type:'checkbox',fixed:'left'},
          {field:'suggestionId',title:'ID',width:100,sort:true},
          {field:'userName',title:'用户名',width:100},
          {field:'userIdType',title:'证件类型',width:100},
          {field:'userIdNum',title:'证件号码',width:100},
          {field:'userPhone',title:'联系方式',width:150},
          {field:'suggestionObject',title:'建议对象',width:100},
          {field:'suggestionText',title:'建议描述',width:100},
          {field:'suggestionTime',title:'建议发布时间',width:150},
          {field:'isdelete',title:'是否被删除',width:100},
          {field:'right',title:'操作',width:150,toolbar:"#barDemoSuggest"}
      ]]
  });
  
	//通过建议搜索，并执行重载
	 var $ = layui.$, activesug = {
		    reload: function(){
		      var demoReload = $('#demoSuggestionReload');
		      console.log(demoReload.val())
		      //执行重载
		      table.reload('demoSuggestion', {
		 	    url:'/12306/SuggestionReload.do?key='+demoReload.val(),
		 	    method:'post',
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		          key: {
		            key: demoReload.val()
		          }
		        }
		      });
		    }
		  };
		  
		  $('.demoSuggestionTable .layui-btn').on('click', function(){
		    var type = $(this).data('type');
		    activesug[type] ? activesug[type].call(this) : '';
		  });
  
 	table.on('tool(testdemoSuggestion)',function(obj){
	    var data = obj.data;
	    //执行逻辑删除
	    if (obj.event === 'del') {
	    	layer.confirm('是否删除？',function(index){
	            var checkStatus = table.checkStatus('demoSuggestion');
	            if (checkStatus.data.length == 0) {
	              layer.msg("请选择要删除的数据！");
	            }else{
	              var suggestionId = checkStatus.data[0].suggestionId;
	              $.ajax({
	                url:'/12306/DelSuggtion.do?suggestionId='+suggestionId,
	                type:'post',
	                dataType:'text',
	                success:function(){
	                  obj.del();
	                  layer.msg("删除成功！");
	                  table.reload('demoSuggestion',{
	                    page:{
	                      curr:tablenameSuggestion.config.page.curr
	                    },
	                    where:{
	                      data:data
	                    }
	                  });
	                },

	                error:function() {
	                 layer.msg("删除失败！")
	                }
	              });
	            }
	          });
	    	
	    }else if(obj.event === "absoluteDel"){ //执行永久删除
	    	layer.confirm('是否删除？',function(index){
	            var checkStatus = table.checkStatus('demoSuggestion');
	            if (checkStatus.data.length == 0) {
	              layer.msg("请选择要删除的数据！");
	            }else{
	              var suggestionIdAb = checkStatus.data[0].suggestionId;
	              $.ajax({
	                url:'/12306/DelAbsoluteSuggtion.do?suggestionIdAb='+suggestionIdAb,
	                type:'post',
	                dataType:'text',
	                success:function(){
	                  obj.del();
	                  layer.msg("删除成功！");
	                  table.reload('demoSuggestion',{
	                    page:{
	                      curr:tablenameSuggestion.config.page.curr
	                    },
	                    where:{
	                      data:data
	                    }
	                  });
	                },

	                error:function() {
	                 layer.msg("删除失败！")
	                }
	              });
	            }
	          });
	    	
	    	
	    }
	    
   });
 	
 	//头工具栏事件
 	  table.on('toolbar(testdemoSuggestion)', function(obj){
 		  var checkStatus = table.checkStatus(obj.config.id);
 		  switch(obj.event){
 		  	case 'delall'://批量删除
 		  		layer.confirm('真的删除已选的数据吗？？', function(index){
 		    		  var data = checkStatus.data;
 		    	        var dataId = [];
 		    	        if(data.length === 0){
 		    	        	layer.msg("请选择所要删出的数据！！");
 		    	        }else{
 		    	        	for (var i = 0; i < data.length; i++) {
 		        	        	dataId.push(data[i].suggestionId);
 		        			}
 		        	        //console.log(dataId)
 		        	        $.ajax({
 		        	        	url:'/12306/DelBatchSuggestion.do? ids'+dataId,
 		        	  	  		data:{"dataId":dataId},
 		        	  	  		traditional:true,
 		        	  	  		type:'post',
 		        	  	  		dataType:'text',
 		        	  	  		
 		        	  	  		success:function(){
 		        		  			layer.msg("删除成功！！");
 		        		  		//重载
 		              	  			table.reload('demoSuggestion', {
 		              	  				page: {
 		              	  					curr: tablenameSuggestion.config.page.curr //重新从当前页开始
 		              	  				}
 		              	  				,where: {
 		              	  					data:data
 		              	  				}
 		              	  				
 		              	  			});
 		        		  		},
 		        		  		
 		        		  		error:function(){
 		        		  			layer.msg("删除失败！！");
 		        		  		}

 		        	        });
 		    	        }
 		    	        
 		    	   });
 		  	
 		  	
 		  	break;
 		  }
 	  });
  
  
	//失信人
 	var loseCreditUserTab = table.render({
 	      elem:"#loseCreditUser",
 	      height:'full-200',
 	      url:'/12306/LoserCreditAdmin.do',
 	      toolbar:'#toolbarlcu',
 	      method:'post',
 	      page:true,
 	      cols:[[
 	          {type:'checkbox',fixed:'left'},
 	          {field:'loseCredit_id',title:'ID',width:100,sort:true},
 	          {field:'user_name',title:'失信人名',width:100},
 	          {field:'user_id_num',title:'失信人身份证号',width:200},
 	          {field:'is_quit',title:'是否被删除',width:100},
 	          {field:'right',title:'操作',width:150,toolbar:"#barDemolcu"}
 	      ]]
 	  });
	
 	//通过失信人搜索，并执行重载
	 var $ = layui.$, activeLcu = {
		    reload: function(){
		      var demoReload = $('#demoLcuReload');
		      console.log(demoReload.val())
		      //执行重载
		      table.reload('loseCreditUser', {
		 	    url:'/12306/LoseCreditReload.do?key='+demoReload.val(),
		 	    method:'post',
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		          key: {
		            key: demoReload.val()
		          }
		        }
		      });
		    }
		  };
		  
		  $('.demoLcuTable .layui-btn').on('click', function(){
		    var type = $(this).data('type');
		    activeLcu[type] ? activeLcu[type].call(this) : '';
		  });
  
 	table.on('tool(loseCreditUserTest)',function(obj){
 		 var data = obj.data;
 		 if (obj.event === 'del') {
 			layer.confirm('是否删除？',function(index){
	            var checkStatus = table.checkStatus('loseCreditUser');
	            if (checkStatus.data.length == 0) {
	              layer.msg("请选择要删除的数据！");
	            }else{
	              var loseCreditId = checkStatus.data[0].loseCredit_id;
	              $.ajax({
	                url:'/12306/DelLoseCredit.do?loseCreditId='+loseCreditId,
	                type:'post',
	                dataType:'text',
	                success:function(){
	                  obj.del();
	                  layer.msg("删除成功！");
	                  table.reload('loseCreditUser',{
	                    page:{
	                      curr:loseCreditUserTab.config.page.curr
	                    },
	                    where:{
	                      data:data
	                    }
	                  });
	                },

	                error:function() {
	                 layer.msg("删除失败！")
	                }
	              });
	            }
	          });
 			 
 		 }else if(obj.event === "absoluteDel"){ //执行永久删除
 			layer.confirm('是否删除？',function(index){
	            var checkStatus = table.checkStatus('loseCreditUser');
	            if (checkStatus.data.length == 0) {
	              layer.msg("请选择要删除的数据！");
	            }else{
	              var loseCreditId = checkStatus.data[0].loseCredit_id;
	              $.ajax({
	                url:'/12306/DelAbsoluteLoseCredit.do?loseCreditId='+loseCreditId,
	                type:'post',
	                dataType:'text',
	                success:function(){
	                  obj.del();
	                  layer.msg("删除成功！");
	                  table.reload('loseCreditUser',{
	                    page:{
	                      curr:loseCreditUserTab.config.page.curr
	                    },
	                    where:{
	                      data:data
	                    }
	                  });
	                },

	                error:function() {
	                 layer.msg("删除失败！")
	                }
	              });
	            }
	          });
 			 
 		 
 		 }
 		  
 	});
 	
 	
 	table.on('toolbar(loseCreditUserTest)', function(obj){
		  var checkStatus = table.checkStatus(obj.config.id);
		  switch(obj.event){
		  	case 'delall'://批量删除
		  		layer.confirm('真的删除已选的数据吗？？', function(index){
		    		  var data = checkStatus.data;
		    	        var dataId = [];
		    	        if(data.length === 0){
		    	        	layer.msg("请选择所要删出的数据！！");
		    	        }else{
		    	        	for (var i = 0; i < data.length; i++) {
		        	        	dataId.push(data[i].loseCredit_id);
		        			}
		        	        //console.log(dataId)
		        	        $.ajax({
		        	        	url:'/12306/DelBatchLcu.do? ids'+dataId,
		        	  	  		data:{"dataId":dataId},
		        	  	  		traditional:true,
		        	  	  		type:'post',
		        	  	  		dataType:'text',
		        	  	  		
		        	  	  		success:function(){
		        		  			layer.msg("删除成功！！");
		        		  		//重载
		              	  			table.reload('loseCreditUser', {
		              	  				page: {
		              	  					curr:loseCreditUserTab.config.page.curr //重新从当前页开始
		              	  				}
		              	  				,where: {
		              	  					data:data
		              	  				}
		              	  				
		              	  			});
		        		  		},
		        		  		
		        		  		error:function(){
		        		  			layer.msg("删除失败！！");
		        		  		}

		        	        });
		    	        }
		    	        
		    	   });
		  	break;
		  	case 'getInsert'://添加失信人信息
		  		 var data = checkStatus.data;
		         /*实现添加*/
		         layer.open({
		         	type:2
		     		,title:'添加失信人员信息'//标题
		     		,content:'insertLcu.jsp'
		     		,maxmin:true//窗口最大化
		     		,skin:'layui-layer-lan'
		     		,area:['500px','500px']//窗口大小
		     		,btn:['确定','取消']//按钮
		         	,yes:function(index,layero){
		         		//回调数值
		     			var lcuId = $(layero).find('iframe')[0].contentWindow.loseCredit_id.value;
		     			var lcuName = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_name").value;
		     			var lcuIdNum = $(layero).find('iframe')[0].contentWindow.document.getElementById("user_id_num").value;
		     			
		     			$.ajax({
		     				url:'/12306/AddLoseCreditUser.do?&lcuName='+lcuName+"&lcuIdNum="+lcuIdNum,
		     				type:'post',
		     				dataType:'text',
		     				success:function(res){
		     					layer.msg("添加成功！！");
		     					setTimeout(function(){
		     						//重载
		               	  			table.reload('loseCreditUser', {
		               	  				page: {
		               	  					curr: loseCreditUserTab.config.page.pages //重新从当前页开始
		               	  				}
		               	  				,where: {
		               	  					data:data
		               	  				}
		               	  			});
		     					})
		     				},
		     				error:function(){
		     					layer.msg("添加失败！！");
		     				}
		     			});
		     			layer.close(index);
		     			
		         	}
		         	,success:function(layero,index){
		         		
		         	}
		         
		         });
		  	break;
		  }
	  });
 	
	//管理员
 	var tableAdmin = table.render({
 	      elem:"#demoAdmin",
 	      height:'full-220',
 	      url:'/12306/AdminAllShow.do',
 	      toolbar:'#toolbarAdmin',
 	      method:'post',
 	      page:true,
 	      cols:[[
 	          {type:'checkbox',fixed:'left'},
 	          {field:'admin_id',title:'ID',width:100,sort:true},
 	          {field:'admin_name',title:'管理员名',width:100},
 	          {field:'admin_password',title:'管理员密码',width:100},
 	          {field:'right',title:'操作',width:150,toolbar:"#barDemoAdmin"}
 	      ]]
 	  });
	
	//通过管理员搜索，并执行重载
 	 var $ = layui.$, active = {
 		    reload: function(){
 		      var demoReload = $('#demoReload');
 		      console.log(demoReload.val())
 		      //执行重载
 		      table.reload('demoAdmin', {
 		 	    url:'/12306/AdminReload.do?adminName='+demoReload.val(),
 		 	    method:'post',
 		        page: {
 		          curr: 1 //重新从第 1 页开始
 		        }
 		        ,where: {
 		          key: {
 		            admin_name: demoReload.val()
 		          }
 		        }
 		      });
 		    }
 		  };
 		  
 		  $('.demoTable .layui-btn').on('click', function(){
 		    var type = $(this).data('type');
 		    active[type] ? active[type].call(this) : '';
 		  });
 		  
 	 
 		  
 	table.on('tool(testAdmin)',function(obj){
 		var data = obj.data;
		 if (obj.event === 'del') {
			layer.confirm('是否删除？',function(index){
	            var checkStatus = table.checkStatus('demoAdmin');
	            if (checkStatus.data.length == 0) {
	              layer.msg("请选择要删除的数据！");
	            }else{
	              var adminId = checkStatus.data[0].admin_id;
	              $.ajax({
	                url:'/12306/DelBatchAdmin.do?adminId='+adminId,
	                type:'post',
	                dataType:'text',
	                success:function(){
	                  obj.del();
	                  layer.msg("删除成功！");
	                  table.reload('demoAdmin',{
	                    page:{
	                      curr:tableAdmin.config.page.curr
	                    },
	                    where:{
	                      data:data
	                    }
	                  });
	                },

	                error:function() {
	                 layer.msg("删除失败！")
	                }
	              });
	            }
	          });
			 
		 }else if (obj.event === 'edit'){
		        layer.open({
		            type:2,
		            title:'编辑管理员信息',
		            content:'editAdmin.jsp',
		            maxmin:true,
		            skin:'layui-layer-lan',
		            area:['350px','600px'],
		            btn:['确定','取消'],
		            yes:function(index,layero){
		               var admin_id = $(layero).find('iframe')[0].contentWindow.admin_id.value;
		               var admin_name = $(layero).find('iframe')[0].contentWindow.document.getElementById("admin_name").value;
		               var admin_password = $(layero).find('iframe')[0].contentWindow.document.getElementById("admin_password").value;
		            
		               obj.update({
		                  "admin_id":admin_id,
		                  "admin_name":admin_name,
		                  "admin_password":admin_password
		               })

		               $.ajax({
		                url:'/12306/UpadteAdmin.do?admin_id='+admin_id+'&admin_name='+admin_name+'&admin_password='+admin_password,
		                type:'post',
		                dataType:'text',
		                data:{
			                  "admin_id":admin_id,
			                  "admin_name":admin_name,
			                  "admin_password":admin_password
		                },
		                success:function(res){
		                  layer.msg("修改成功！");
		                  table.reload('demoAdmin',{
		                    page:{
		                      curr:tableAdmin.config.curr
		                    },
		                    where:{
		                      data:data
		                    }
		                  });
		                },
		                error:function(){
		                  layer.msg("修改失败！");
		                }
		               })
		               layer.close(index);

		            },
		            success:function(layero,index){
		              var div = layero.find('iframe').contents().find("#Admin");
		              var body = layer.getChildFrame('body',index);
		              var ifrandWindow = window['layui-layer-iframe'+index];
		              body.find('#admin_id').val(data.admin_id);
		              body.find('#admin_name').val(data.admin_name);
		              body.find('#admin_password').val(data.admin_password);
		            }
		          });
		 }
	
 	});
 	
 	//头部工具栏
 	table.on('toolbar(testAdmin)', function(obj){
 		var checkStatus = table.checkStatus(obj.config.id);
 		 switch(obj.event){
 			case 'getInsert'://添加失信人信息
	  		 var data = checkStatus.data;
	         /*实现添加*/
	         layer.open({
	         	type:2
	     		,title:'添加管理人员'//标题
	     		,content:'addAdmin.jsp'
	     		,maxmin:true//窗口最大化
	     		,skin:'layui-layer-lan'
	     		,area:['500px','500px']//窗口大小
	     		,btn:['确定','取消']//按钮
	         	,yes:function(index,layero){
	         		//回调数值
	     			var admin_id = $(layero).find('iframe')[0].contentWindow.admin_id.value;
	     			var admin_name = $(layero).find('iframe')[0].contentWindow.document.getElementById("admin_name").value;
	     			var admin_password = $(layero).find('iframe')[0].contentWindow.document.getElementById("admin_password").value;
	     			
	     			$.ajax({
	     				url:'/12306/AddAdmin.do?&admin_name='+admin_name+"&admin_password="+admin_password,
	     				type:'post',
	     				dataType:'text',
	     				success:function(res){
	     					layer.msg("添加成功！！");
	     					setTimeout(function(){
	     						//重载
	               	  			table.reload('demoAdmin', {
	               	  				page: {
	               	  					curr: tableAdmin.config.page.pages //重新从当前页开始
	               	  				}
	               	  				,where: {
	               	  					data:data
	               	  				}
	               	  			});
	     					})
	     				},
	     				error:function(){
	     					layer.msg("添加失败！！");
	     				}
	     			});
	     			layer.close(index);
	     			
	         	}
	         	,success:function(layero,index){
	         		
	         	}
	         
	         });
	  		break;
 			case 'delall'://批量删除
		  		layer.confirm('真的删除已选的数据吗？？', function(index){
		    		  var data = checkStatus.data;
		    	        var dataId = [];
		    	        if(data.length === 0){
		    	        	layer.msg("请选择所要删出的数据！！");
		    	        }else{
		    	        	for (var i = 0; i < data.length; i++) {
		        	        	dataId.push(data[i].admin_id);
		        			}
		        	        //console.log(dataId)
		        	        $.ajax({
		        	        	url:'/12306/DelBatchAdmins.do? ids'+dataId,
		        	  	  		data:{"dataId":dataId},
		        	  	  		traditional:true,
		        	  	  		type:'post',
		        	  	  		dataType:'text',
		        	  	  		
		        	  	  		success:function(){
		        		  			layer.msg("删除成功！！");
		        		  		//重载
		              	  			table.reload('demoAdmin', {
		              	  				page: {
		              	  					curr:tableAdmin.config.page.curr //重新从当前页开始
		              	  				}
		              	  				,where: {
		              	  					data:data
		              	  				}
		              	  				
		              	  			});
		        		  		},
		        		  		
		        		  		error:function(){
		        		  			layer.msg("删除失败！！");
		        		  		}

		        	        });
		    	        }
		    	        
		    	   });
		  	break;
 		 }
 	});
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
  
  
  
  
  
  
  
});

/* 判断是否登录 */
$(function(){
	if($("#adminUserName").text() == ""){
		window.location.href="loginAdmin.html";
	}
})



</script>

</body>
<!-- 管理员 -->
<script type="text/html" id="barDemoAdmin">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script> 

<script type="text/html" id="toolbarAdmin">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delall">批量删除数据</button>
	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="getInsert">添加管理员</button>
	
  </div>
</script>

<!-- 用户 -->
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script> 

<script type="text/html" id="toolbarDemo1">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delall">批量删除数据</button>
  </div>
</script>

<!-- 建议 -->
<script type="text/html" id="barDemoSuggest">
  <a class="layui-btn layui-btn-xs" lay-event="absoluteDel">永久删除</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="toolbarSuggest">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delall">批量删除数据</button>
  </div>
</script>

<!-- 失信人 -->
<script type="text/html" id="barDemolcu">
  <a class="layui-btn layui-btn-xs" lay-event="absoluteDel">永久删除</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="toolbarlcu">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delall">批量删除数据</button>
	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="getInsert">添加失信人员</button>
	
  </div>
</script>
 
</html>